const {fork} = require('child_process');
const path = require('path');
//两个进程监听同一个服务
const child = fork('socket.js', {
  cwd: path.join(__dirname, 'test')
});

const net = require('net');

net.createServer((socket) => {
  if(Math.random()>.5){
    socket.write('father process');
  }else{
    child.send('socket', socket/* 可以是Socket|Server */ ); // 向子进程发消息
  }
}).listen(3000);

